import { createApp } from "vue";
import pinia from "./stores";
import ElementPlus from "element-plus";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import "element-plus/dist/index.css";
import App from "./App.vue";
import router from "./router";
import "./styles/index.scss";
import ElSvg from "./components/SvgIcon/ElSvg";
import "./permission";
import { useUserInfoStore } from "./stores/userInfo";
const app = createApp(App);

//按钮的权限:  自定义一个全局自定义指令
//第一个参数:自定义指令的名字
//第二个参数:配置项   有两种写法
//()=>  这种写法会默认执行两次
//{} 这种写法会提供几种钩子 (可选的)
app.directive("visite", {
  //挂载完毕:当使用指令的节点挂载完毕.执行一次
  mounted(el, binding) {
    //includes() 判断有没有这个值
    if (!useUserInfoStore().buttonsList.includes(binding.value)) {
      //parentNode 可以返回某个节点的父节点 没有父节点返回 null
      //removeChild 类似于v-if 直接从DOM树上干掉
      el.parentNode.removeChild(el);
    }
  },
});
import "./mock/mockServe";

//vue-echarts设置
import ECharts from "vue-echarts";
import { use } from "echarts/core";

// import ECharts modules manually to reduce bundle size
import { CanvasRenderer } from "echarts/renderers";
import { BarChart } from "echarts/charts";
import { GridComponent, TooltipComponent } from "echarts/components";
import { LineChart } from "echarts/charts";
import { TitleComponent } from "echarts/components";

import { LegendComponent } from 'echarts/components';
import { RadarChart } from 'echarts/charts';
import { CandlestickChart } from 'echarts/charts';
import { PieChart } from 'echarts/charts';

use([
  CanvasRenderer,
  BarChart,
  GridComponent,
  TooltipComponent,
  LineChart,
  TitleComponent,
  LegendComponent,
  RadarChart,
  CandlestickChart,
  PieChart
]);
//全局组件v-chart
app.component("v-chart", ECharts);

ElSvg(app);
app
  .use(pinia)
  .use(router)
  .use(ElementPlus, {
    locale: zhCn,
  })
  .mount("#app");
